package com.tenement.entity;

import com.mybatisflex.annotation.*;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

/**
 *  实体类。
 *
 * @author BertXie
 * @since 1.0.1
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(value = "sys_dept",dataSource = "tenement")
public class Dept implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id(keyType = KeyType.Generator, value = "snowFlakeId")
    @ColumnAlias(value = "deptId")
    private Long id;

    @ColumnAlias(value = "deptPId")
    private Long pId;

    @ColumnAlias(value = "deptAncestors")
    private String ancestors;

    @NotBlank(message = "部门名称不能为空")
    private String name;

    private Integer sortOrder;

    @NotBlank(message = "负责人不能为空")
    private String leader;

    @NotBlank(message = "联系方式不能为空")
    @Pattern(regexp = "^(1[3-9]\\d{9})$",message = "手机号码格式错误")
    private String phone;

    @NotBlank(message = "邮箱不能为空")
    @Pattern(regexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",message = "邮箱格式有误")
    private String email;

    private String creator;

    @Column(onInsertValue = "now()")
    private Timestamp createTime;

    @Column(onUpdateValue = "now()")
    private Timestamp updateTime;

    @Column(tenantId = true)
    private Long tenementId;

    @Column(ignore = true)
    private List<Dept> children;

}
